<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.io.*, java.sql.*, java.util.*,LS.*, java.util.List" %>
<%request.setCharacterEncoding("utf-8");%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
session.setAttribute("user",null);
session.setAttribute("departments_id", null);
session.setAttribute("departments_id2", null);
session.setAttribute("level", null);
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	
	<link href="assets/css/top.css" rel="stylesheet">
	<link href="assets/css/bootstrap.css" rel="stylesheet">
	<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
	<link href="assets/css/docs.css" rel="stylesheet">
	
	<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
	<script type="text/javascript" src="assets/smartPop/jquery.smartPop.js"></script>
	<link rel="stylesheet" href="assets/smartPop/jquery.smartPop.css" />
</head>
<body>
<!-- 메뉴
    ================================================== -->
	<div class="navbar navbar-inverse navbar-fixed-top" style="font-size:20px;">
		<div class="navbar-inner">
			<div class="container" id="menubar">
				<button type="button" class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse" style="float:left">
					<span class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
<!-- 				<a class="brand" href="index.jsp" style="float:left">기자재대여 from skhu</a> -->
				<div class="nav-collapse collapse">
					<ul class="nav">
						<li class="active"><a href="/LSsystem/index.do">HOME</a></li>
						<li class="dropdown"><a class="dropdown-toggle"
							data-toggle="dropdown" href=""> 공지사항<b class="caret"></b>
						</a>
							<ul class="dropdown-menu">
								<li><a href="/LSsystem/notice.do">공지사항</a></li>
							</ul></li>
					</ul>
				</div>
				<form  id="frm1" class="form-inline" method="post" style="text-align: right;margin:0px;">
					<div class="login">
						<b id="logb">
						아이디 <input type="text" name="id" class="input-small"  placeholder="ID">
						비밀번호 <input type="password" name="password" class="input-small"  placeholder="Password"></b>
						<button type="submit" id="login" class="btn" style="margin:3px;">로그인</button>						
					</div>
				</form>
			</div>
		</div>
	</div>
	<%
if(request.getParameter("id")!=null){
	if(request.getParameter("password")!=null){
		String id = request.getParameter("id");
		String pw = request.getParameter("password");
		String url = "index.do";
		String errMsg = "";
		
		if(id == null){
			id = "";
			pw = "";
		}else{

			Users u = UsersHome.selectById(id);
			int udd1 = 0;
			int udd2 = 0;
			
			
			if(vwUDDHome.departments_name(id).size() == 1){
				udd1 = vwUDDHome.departments_name(id).get(0).getDepartments_id();
			}else if(vwUDDHome.departments_name(id).size() == 2){
				udd1 = vwUDDHome.departments_name(id).get(0).getDepartments_id();
				udd2 = vwUDDHome.departments_name(id).get(1).getDepartments_id();
			}else{
				
			}
			
			if(u==null){%>
				<script>
					window.alert("유저의 아이디가 존재하지 않습니다.");
					history.go(-1);
				</script>
			<% }else if(!pw.equals(u.getPassword())){%>
				<script>
				window.alert("패스워드가 틀립니다.");
				history.go(-1);
				</script>
			<% }else{

				String level = u.getUser_position();
				session.setAttribute("user",null);
				session.setAttribute("departments_id", null);
				session.setAttribute("departments_id2", null);
				session.setAttribute("level", null);
				
				session.setAttribute("level", level);
				session.setAttribute("user", u);
				session.setAttribute("userid", id);
				session.setAttribute("departments_id", udd1);
				if(vwUDDHome.departments_name(id).size() == 2){
					session.setAttribute("departments_id2", udd2);
				}
				
				%>
					<script>
						 document.getElementById("frm1").submit();
					</script>
				<%
				
				return;
			}
		}
	}
}
%>
	<!-- javascript -->
	
	<script src="assets/js/bootstrap-dropdown.js"></script>
		<script type="text/javascript">
		$(document).ready(function() {
			$('.dropdown-toggle').dropdown();
		});
		</script>
</body>
</html>